/** 
 * 订单附件
 */
import orderApi from '@/config/server/api/order'

// 订单附件
let fileType = {
  channelImages: '渠道带看单',
  networkCredentialsImages: '网络获客凭证',
  subscriptionImages: '认购单',
  subscriptionCreditImages: '认购收据及POS单',
  contractAffirmNetworkImages: '合同关键页&签约确认单（网签）',
  contractAffirmInitialImages: '合同关键页&签约确认单（草签）',
  billOfCreditImages: '签约收据及POS单',
  satisfactionSurveyImages: '客户满意度调查表',
  specialApplicationImages: '特殊申请',
}

// 订单附件
function list(id, type) {
  return orderApi.orderfile.list.fetch({
    id,
    type
  }).then(res => {
    let data = res.map(item => ({
      ...item,
      attachAddress: JSON.parse(item.attachAddress),
      name: fileType[item.attachType],
    }))
    return data
  })
}

// 编辑订单附件
function update({ businessId, orAnnexReqs }) {
  return orderApi.orderfile.update.fetch({
    businessId,
    orAnnexReqs
  }).then(res => {
    return res
  })
}

export default {
  list,
  update
}
